package com.corona.game;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.corona.Game;

import java.util.Iterator;

/* compiled from: PkmnMap.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/DrawReflections.class */
public class DrawReflections extends Action {
    Sprite blankSprite;
    Pixmap pixels;
    Texture texture;
    Tile tile;
    int temp1;
    int temp2;
    public Action.Layer layer = Action.Layer.map_142;
    Color prevColor = new Color();
    public int regionWidth = 8;
    public int middleWidth = 1;
    public float uvWidth1 = 1.0f;
    public float uvWidth2 = 1.0f;

    public DrawReflections(Game game) {
        super(new Object[0]);
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        if (game.map.timeOfDay.equals("night")) {
            game.currCloudTexture = game.nightTexture;
        }
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (!game.player.dontDrawMapDuringBattle && game.map.tiles == game.map.overworldTiles) {
            this.prevColor.set(game.mapBatch.getColor());
            game.mapBatch.setColor(this.prevColor.r, this.prevColor.g, this.prevColor.b, 0.5f);
            Iterator<Pokemon> it = game.map.onscreenPokemon.iterator();
            while (it.hasNext()) {
                Pokemon pokemon = it.next();
                if (pokemon.currOwSprite != null && !pokemon.types.contains("GHOST")) {
                    drawWithRipple(game, pokemon.currOwSprite, pokemon.position.x, (pokemon.position.y - 4.0f) - ((float) (pokemon.currOwSprite.getRegionHeight() - 8)));
                }
            }
            Iterator<Tile> it2 = game.map.onscreenTiles.iterator();
            while (it2.hasNext()) {
                Tile tile = it2.next();
                this.tile = tile;
                if (this.tile.overSprite != null && !this.tile.drawUpperBelowPlayer) {
                    if (game.rippleTimer < 9) {
                        game.mapBatch.draw(tile.overSprite.getTexture(), tile.overSprite.getX(), tile.overSprite.getY() - ((float) (tile.overSprite.getRegionHeight() - 8)), tile.overSprite.getWidth(), tile.overSprite.getHeight(), tile.overSprite.getRegionX(), tile.overSprite.getRegionY(), tile.overSprite.getRegionWidth(), tile.overSprite.getRegionHeight(), false, true);
                    } else if (game.rippleTimer < 24) {
                        this.regionWidth = tile.overSprite.getRegionWidth() / 2;
                        this.middleWidth = 1;
                        game.mapBatch.draw(tile.overSprite.getTexture(), tile.overSprite.getX(), tile.overSprite.getY() - ((float) (tile.overSprite.getRegionHeight() - 8)), (float) this.regionWidth, tile.overSprite.getHeight(), tile.overSprite.getRegionX(), tile.overSprite.getRegionY(), this.regionWidth, tile.overSprite.getRegionHeight(), false, true);
                        game.mapBatch.draw(tile.overSprite.getTexture(), tile.overSprite.getX() + ((float) this.regionWidth), tile.overSprite.getY() - ((float) (tile.overSprite.getRegionHeight() - 8)), (float) this.middleWidth, tile.overSprite.getHeight(), tile.overSprite.getRegionX() + this.regionWidth, tile.overSprite.getRegionY(), this.middleWidth, tile.overSprite.getRegionHeight(), false, true);
                        game.mapBatch.draw(tile.overSprite.getTexture(), tile.overSprite.getX() + ((float) this.regionWidth) + ((float) this.middleWidth), tile.overSprite.getY() - ((float) (tile.overSprite.getRegionHeight() - 8)), (float) this.regionWidth, tile.overSprite.getHeight(), tile.overSprite.getRegionX() + this.regionWidth, tile.overSprite.getRegionY(), this.regionWidth, tile.overSprite.getRegionHeight(), false, true);
                    } else if (game.rippleTimer < 33) {
                        game.mapBatch.draw(tile.overSprite.getTexture(), tile.overSprite.getX(), tile.overSprite.getY() - ((float) (tile.overSprite.getRegionHeight() - 8)), tile.overSprite.getWidth(), tile.overSprite.getHeight(), tile.overSprite.getRegionX(), tile.overSprite.getRegionY(), tile.overSprite.getRegionWidth(), tile.overSprite.getRegionHeight(), false, true);
                    } else if (game.rippleTimer < 48) {
                        this.regionWidth = tile.overSprite.getRegionWidth() / 2;
                        this.middleWidth = 1;
                        game.mapBatch.draw(tile.overSprite.getTexture(), tile.overSprite.getX() + ((float) this.middleWidth), tile.overSprite.getY() - ((float) (tile.overSprite.getRegionHeight() - 8)), (float) (this.regionWidth - this.middleWidth), tile.overSprite.getHeight(), tile.overSprite.getRegionX(), tile.overSprite.getRegionY(), this.regionWidth - this.middleWidth, tile.overSprite.getRegionHeight(), false, true);
                        game.mapBatch.draw(tile.overSprite.getTexture(), tile.overSprite.getX() + ((float) this.regionWidth), tile.overSprite.getY() - ((float) (tile.overSprite.getRegionHeight() - 8)), (float) this.regionWidth, tile.overSprite.getHeight(), tile.overSprite.getRegionX() + this.regionWidth, tile.overSprite.getRegionY(), this.regionWidth, tile.overSprite.getRegionHeight(), false, true);
                    }
                }
            }
            if (!(game.player.hmPokemon == null || game.player.hmPokemon.currOwSprite == null)) {
                if (game.player.flyingAction != null) {
                    if (game.player.dirFacing.equals("down")) {
                        drawWithRipple(game, game.player.flyingAction.spritePart, game.player.position.x + ((float) game.player.flyingAction.xOffset2) + ((float) game.player.flyingAction.xOffset), (((game.player.position.y - 6.0f) - 21.0f) - ((float) game.player.flyingAction.yOffset2)) - ((float) game.player.flyingAction.yOffset));
                    }
                    drawWithRipple(game, game.player.hmPokemon.currOwSprite, game.player.hmPokemon.position.x, ((game.player.position.y - 16.0f) - ((float) game.player.flyingAction.yOffset)) - ((float) (game.player.hmPokemon.currOwSprite.getRegionHeight() - 8)));
                    if (!game.player.dirFacing.equals("down") || game.player.flyingAction.pokemon.specie.name.equals("mantine")) {
                        drawWithRipple(game, game.player.flyingAction.spritePart, game.player.position.x + ((float) game.player.flyingAction.xOffset2) + ((float) game.player.flyingAction.xOffset), (((game.player.position.y - 6.0f) - 21.0f) - ((float) game.player.flyingAction.yOffset2)) - ((float) game.player.flyingAction.yOffset));
                    }
                } else if (!game.player.currFieldMove.equals("RIDE") && !game.player.hmPokemon.types.contains("GHOST")) {
                    drawWithRipple(game, game.player.hmPokemon.currOwSprite, game.player.hmPokemon.position.x, (game.player.hmPokemon.position.y - 4.0f) - ((float) (game.player.hmPokemon.currOwSprite.getRegionHeight() - 8)));
                }
            }
            if (game.player.flyingAction == null) {
                drawWithRipple(game, game.player.currSprite, game.player.position.x, (game.player.position.y - 4.0f) - ((float) (game.player.currSprite.getRegionHeight() - 8)));
            }
            game.mapBatch.setColor(this.prevColor);
        }
    }

    public void drawWithRipple(Game game, Sprite sprite, float x, float y) {
        if (game.rippleTimer < 9) {
            game.mapBatch.draw(sprite.getTexture(), x, y, (float) sprite.getRegionWidth(), (float) sprite.getRegionHeight(), sprite.getU(), sprite.getV(), sprite.getU2(), sprite.getV2());
        } else if (game.rippleTimer < 24) {
            this.uvWidth1 = sprite.getU2() - sprite.getU();
            this.uvWidth2 = this.uvWidth1 / 16.0f;
            this.uvWidth1 /= 2.0f;
            game.mapBatch.draw(sprite.getTexture(), x, y, 9.0f, (float) sprite.getRegionHeight(), sprite.getU(), sprite.getV(), sprite.getU2() - (this.uvWidth1 - this.uvWidth2), sprite.getV2());
            game.mapBatch.draw(sprite.getTexture(), x + 8.0f + 1.0f, y, 8.0f, (float) sprite.getRegionHeight(), sprite.getU() + this.uvWidth1, sprite.getV(), sprite.getU2(), sprite.getV2());
        } else if (game.rippleTimer < 33) {
            game.mapBatch.draw(sprite.getTexture(), x, y, (float) sprite.getRegionWidth(), (float) sprite.getRegionHeight(), sprite.getU(), sprite.getV(), sprite.getU2(), sprite.getV2());
        } else if (game.rippleTimer < 48) {
            this.uvWidth1 = sprite.getU2() - sprite.getU();
            this.uvWidth2 = this.uvWidth1 / 16.0f;
            this.uvWidth1 /= 2.0f;
            game.mapBatch.draw(sprite.getTexture(), x + 1.0f, y, 7.0f, (float) sprite.getRegionHeight(), sprite.getU(), sprite.getV(), (sprite.getU2() - this.uvWidth1) - this.uvWidth2, sprite.getV2());
            game.mapBatch.draw(sprite.getTexture(), x + 8.0f, y, 8.0f, (float) sprite.getRegionHeight(), sprite.getU() + this.uvWidth1, sprite.getV(), sprite.getU2(), sprite.getV2());
        }
    }
}
